package com.wxm.killing.mq.common.model;

import com.github.pagehelper.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @author: wxm
 * @date: 2019/10/10 8:29
 * @version: 1.0
 */
@Data
public class CommPager<T> implements Serializable {
    private static final long serialVersionUID = -224189960966026897L;
    private long totalRecord;
    private int totalPage;
    private int pageIndex;
    private int currenRecords;
    private int pageSize;
    private List<T> records;

    public CommPager() {
        this.records = new ArrayList();
        this.totalRecord = -1L;
        this.pageSize = -1;
        this.totalPage = -1;
        this.pageIndex = -1;
    }

    public CommPager(List<T> list) {
        if(list instanceof Page) {
            Page<T> page = (Page)list;
            this.records = page.getResult();
            this.currenRecords = page.size();
            this.pageSize = page.getPageSize();
            this.pageIndex = page.getPageNum();
            if(page.isCount()) {
                this.totalRecord = page.getTotal();
                this.totalPage = page.getPages();
            } else {
                this.totalRecord = -1L;
                this.totalPage = -1;
            }
        }

    }

    public CommPager(Page page, List<T> list) {
        this.records = list;
        this.currenRecords = list.size();
        this.pageSize = page.getPageSize();
        this.pageIndex = page.getPageNum();
        this.totalRecord = page.getTotal();
        this.totalPage = page.getPages();
    }

    public long getTotalRecord() {
        return this.totalRecord;
    }

    public void setTotalRecord(long totalRecord) {
        this.totalRecord = totalRecord;
    }

    public int getTotalPage() {
        return this.totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageIndex() {
        return this.pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getRecords() {
        return this.records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public int getCurrenRecords() {
        return this.currenRecords;
    }

    public void setCurrenRecords(int currenRecords) {
        this.currenRecords = currenRecords;
    }
}
